package zjs.dc.controller;

import org.apache.spark.sql.SparkSession;

/**
 * @Class:
 * @Author: kongcb
 * @Description: 工商统计:t_eci_count
 * @Date: 2021/12/15 9:21
 */
public class TEciCount {
    public static void main(String[] args) {
        SparkSession spark = SparkSession.builder().appName("t_eci_count").enableHiveSupport().getOrCreate();
        spark.sparkContext().setLogLevel("ERROR");
        //企业工商数据t_eci_company
        spark.sql("select company_id,company_name from a_dc_ep_ods.t_eci_company").createOrReplaceTempView("eci_company");
        //企业工商数据t_eci_partner
        spark.sql("select company_id,count(1) cn from a_dc_ep_dwi.t_eci_partner group by company_id").createOrReplaceTempView("eci_partner");
        //企业工商数据t_eci_employee
        spark.sql("select company_id,count(1) cn from a_dc_ep_dwi.t_eci_employee group by company_id").createOrReplaceTempView("eci_employee");
        //企业工商数据t_eci_branch
        spark.sql("select company_id,count(1) cn from a_dc_ep_dwi.t_eci_branch group by company_id").createOrReplaceTempView("eci_branch");
        //企业工商数据t_eci_change
        spark.sql("select company_id,count(1) cn from a_dc_ep_dwi.t_eci_change group by company_id").createOrReplaceTempView("eci_change");
        //企业工商数据t_investinfo
        spark.sql("select company_id,count(1) cn from a_dc_ep_dwi.t_investinfo group by company_id").createOrReplaceTempView("investinfo");
        //企业工商数据t_annual_report
        spark.sql("select company_id,count(1) cn from a_dc_ep_dwi.t_annual_report group by company_id").createOrReplaceTempView("annual_report");

        spark.sql("insert overwrite table a_dc_ep_incr.t_eci_count select a.company_id,a.company_name,b.cn,c.cn,d.cn,e.cn,f.cn,g.cn from eci_company a " +
                "left join eci_partner b on a.company_id = b.company_id " +
                "left join eci_employee c on a.company_id = c.company_id " +
                "left join eci_branch d on a.company_id = d.company_id " +
                "left join eci_change e on a.company_id = e.company_id " +
                "left join investinfo f on a.company_id = f.company_id " +
                "left join annual_report g on a.company_id = g.company_id");
        spark.stop();
    }
}
